const xlsx = require('node-xlsx');
var fs = require('fs');
const data = [
     "pt_sl_lineup_phychem_stdval",
    "pt_sl_lineup_phy_cond",
    "pt_sl_lineup_phydim_stdval",
    "pt_sl_lineup_phy_item",
    "pt_sl_lineup_phy_main",
    "pt_sl_lineup_phy_stdval",
    "pt_sl_lineup_sample_cond",
    "pt_sl_msc_gj",
    "pt_sl_msc_gj_detl",
    "pt_sl_msc_he",
    "pt_sl_msc_hr",
    "pt_sl_msc_process",
    "pt_sl_msc_stl",
    "pt_sl_msc_line",
    "pt_sl_msc_hm",
    "pt_sl_msc_hf",
    "pt_sl_msc_jg",
    "pt_sl_msc_hr_steel",
    "pt_tm_roll_steel_grade"
];
const countSql = [];
const columns1 = [];
for(const item of data){
    const tableNameSL = item.replace('pt_','');
    columns1.push(tableNameSL)
    const sql = `
    (select count(1) from CGXZCUSER.${tableNameSL} a
        inner join CGXZCUSER.${item} b on a.id = b.id) ${item}Count
    `
    countSql.push(sql)
}

const countAllSql = `
    select ${countSql.reduce((a,b)=>a+","+b)} from dual
`

var buffer = xlsx.build([
    {name:'列名称',data:[data,columns1]},
]);
 fs.writeFileSync('./列名统计.xlsx',buffer,{'flag':'w'});